import { APP_ID } from '@/constants'
import { instance, unwrap } from './utils'

export async function wxlogin(code: string) {
  const res = await instance.post<API.Res<Data>>('/wxApp/user/getUserInfo', null, {
    params: { code, appId: APP_ID },
  })

  return unwrap(res)
}

export async function postPhone(code: string) {
  const res = await instance.post<API.Res<Data>>('/wxApp/user/getPhone', null, {
    params: { code, appId: APP_ID },
  })

  return unwrap(res)
}

export async function bindInfo() {
  const res = await instance.post<API.Res<Data>>('/car/consumerUser/getConsumerBindInfo')

  return unwrap(res)
}

export async function getUserInfo(openid: string) {
  const res = await instance.post<API.Res<Data>>('/car/consumerUser/getConsumerUserByOpenId', null, {
    params: { openId: openid },
  })

  return unwrap(res)
}

export async function updateUserInfo(data: Data) {
  const res = await instance.post<API.Res<Data>>('/car/consumerUser/editConsumerUser', data)

  return unwrap(res)
}
